package com.szqhyxj.youxiangju.sys.imag;

import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.support.annotation.NonNull;

import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;

import java.security.MessageDigest;

/**
 * 当宽小于高3分钟2时旋转
 * XiaoPanYu
 * on 2018/11/6
 */
public class RotateTransformation extends BitmapTransformation{
    private float rotateRotationAngle = 0f;
    public RotateTransformation( float rotateRotationAngle) {
        super();
        this.rotateRotationAngle = rotateRotationAngle;
    }

    @Override
    protected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight){
                Matrix matrix = new Matrix();

                if(toTransform.getWidth()<(toTransform.getHeight()*4/5))
                    matrix.postRotate(rotateRotationAngle);
                return Bitmap.createBitmap(toTransform, 0, 0, toTransform.getWidth(), toTransform.getHeight(), matrix, true);
    }

    @Override
    public void updateDiskCacheKey(@NonNull MessageDigest messageDigest){

    }
    //    @Override protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
//
//
//        Matrix matrix = new Matrix();
//        if(outWidth<(outHeight*2/3))
//            matrix.postRotate(rotateRotationAngle);
//        return Bitmap.createBitmap(toTransform, 0, 0, toTransform.getWidth(), toTransform.getHeight(), matrix, true);
//    }
//
//    @Override
//    public void updateDiskCacheKey(@NonNull MessageDigest messageDigest){
//
//    }
}
